home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
ping.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
5KB
|
124 lines
<?php
/**
* Ping script
* Script periodically "async" called by menuFrame.php to inform server that user is still connected
* return empty XML response file
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.0.0
*/
//cfDebugSingle('PING '.$_SERVER['HTTP_USER_AGENT']);
// Ping server
if(isset($_GET['checkServer'])){
$output='serverOnline';
// Check secret key
if(!customIssetKey()) $output.='keyNotSet';
// Ping BitTorrent seeder ($_GET['checkSeeder'] is bittorrent seeder port number)
if(isset($_GET['checkSeeder']) && is_numeric($_GET['checkSeeder'])){
// Set info that seeder is being checked so debug info is not displayed by seeder
cfMSetVar('checkingSeeder',time());
// Open a connection on seeder to see if it's responding
if($sock=@fsockopen('127.0.0.1',$_GET['checkSeeder'],$errno,$errstr,3)){
fclose($sock);
$output.='seederOnline';
}
else $output.='seederOffline';
}
// Clear APC cache
if(function_exists('apc_cache_info')){
$cl=@apc_cache_info();
$latest=0;
if(isset($cl['cache_list'])){
// Check for last access time (except ping scripts)
foreach ($cl['cache_list'] as $v){
$bn=basename($v['filename']);
if($bn!='ping.php' && $bn!='security.php' && $bn!='commonFunctions.php' && $bn!='bittorrentSeeder.php' && $bn!='test.php' && $v['access_time']>$latest) $latest=$v['access_time'];
}
// If last access time older than APCTTL, clear cache
if($latest>0 && cfGGetVar('APCTTL') && is_numeric(cfGGetVar('APCTTL')) && (time()-$latest)>cfGGetVar('APCTTL'))
apc_clear_cache();
}
}
echo $output;
exit;
}
// External server access test
elseif(isset($_GET['check'])) die('<ping>ok:'.cfGGetVar('LANIPComputed').'</ping>');
// Wake on Wan test
elseif(isset($_GET['wow'])) die('<script type="text/javascript">parent.connected()</script>');
// Image used to detect that computer is awakened and server responding, after wake-up command sent
elseif(isset($_GET['wowImg'])) {
header('P3P: policyref="/w3c/p3p.xml",CP="NON COR CURa OUR NOR NAV"');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header('Content-type: image/gif');
imagegif(imagecreate(1,50));
exit;
}
// If session file doesn't exist anymore (destroyed on server), inform user that he has been logged out
if(!isset($_COOKIE["WSESSID"]) ||
(cfGGetVar('sessionHandler')=='memory' && !cfMIssetVar('weezoSess_'.$_COOKIE["WSESSID"])) ||
!file_exists(cfAppDataDir().'/sessiondata/sess_'.$_COOKIE["WSESSID"])){
// Response XML header
cfAsyncHeader();
// Inform user
echo cfAsyncXMLJSaction('if(W.pingInt) clearInterval(pingInt)');
// Stop pinging
echo cfAsyncXMLJSaction('if(!W.disconnectionSent) {disconnectionSent=1;alert("'.cfCaption('logUserLogout').' '.@strftime('%Hh %Mm %Ss', mktime()).'");};if(parent) parent.location.href="/index.php"; else location.href="/index.php";');
echo cfAsyncFooter();
// Make sure memory and files are cleared
if(isset($_COOKIE["WSESSID"])){
if(cfGGetVar('sessionHandler')=='memory' && cfMIssetVar('weezoSess_'.$_COOKIE["WSESSID"])) cfMUnsetVar('weezoSess_'.$_COOKIE["WSESSID"]);
if(file_exists(cfAppDataDir().'/sessiondata/sess_'.$_COOKIE["WSESSID"])) @unlink(cfAppDataDir().'/sessiondata/sess_'.$_COOKIE["WSESSID"]);
}
exit();
}
// Inform application
$res=cfPingUpdate();
// Check if a resource force-open is required by server
if(cfMIssetVar('weezoChatForceOpen'.$_COOKIE["WSESSID"])){
wSession_start();
// Response XML header
cfAsyncHeader();
foreach(cfResourcesGetUser() as $id=>$value){
if($value['resourceName'].'.res'==cfMGetVar('weezoChatForceOpen'.$_COOKIE["WSESSID"])){
if(cfTGetVar('frames')) echo cfAsyncXMLJSaction($value['resourceJsLink']);
else echo cfAsyncXMLJSaction('document.location="/res/'.$value['type'].'/'.$value['subType'].'/'.$value['baseFile']);
}
}
cfMUnsetVar('weezoChatForceOpen'.$_COOKIE["WSESSID"]);
}
else {
// Response XML header
cfAsyncHeader();
}
// If server connection failed, send warning to browser
if($res===NULL) echo cfAsyncXMLJSaction('if(dgi(\'rSPb\')) dgi(\'rSPb\').style.display="block";dgi(\'rSPb\').innerHTML="App. not resp.:'.strftime('%Hh %Mm %Ss', mktime()).'";');
// All OK: hide alert div
else echo cfAsyncXMLJSaction('if(dgi(\'rSPb\')) dgi(\'rSPb\').style.display="none"');
echo cfAsyncFooter();